export {}
console.log('7.Typeof,keyof的活用方法和重要提示==========================')
// type 定义类型别名
type V7 = (number | string)[]
let v71: V7 = [1, '2', 3]
let v72: V7 = ['1', '2', '3']

type V721 = boolean[]
let v721: V721 = [true, false, true]

type Age722 = number
type Person722 = {
  name: string
  age: Age722
  sayHello?: () => void
}
let v722: Person722 = {
  name: '张三',
  age: 18,
}

console.log(typeof v722) // object

// 获取函数类型
function add(a: number, b: number): number {
  return a + b
}
console.log(typeof add) // function
type V73AddType = typeof add //add(): (a: number, b: number) => number
let v731: V73AddType
v731 = (a: number, b: number) => a + b
console.log(v731(1, 2)) //3

// keyof 获取对象类型的属性名
type V74Person = {
  name: string
  age: number
}
type V74Param = keyof V74Person // 'name' | 'age'
let v741: V74Param = 'name'
let v742: V74Param = 'age'
// let v43: V4Param = 'dj' // Error: Type '"dj"' is not assignable to type '"name" | "age"'.

console.log(v743GetParam('name'))
console.log(v743GetParam('age'))

function v743GetParam(key: V74Param): string {
  return `${key} ${v722[key]}`
}

console.log()
console.log()
console.log('8.联合类型和交叉类型=========================================')
// 联合类型
console.log(v81('11111111111'))
console.log(v81(11111111111))
function v81(a: number | string): string {
  return a.toString()
}

type Direction = 'North' | 'East' | 'South' | 'West'
function v82(direction: Direction) {
  console.log(direction)
}
v82('North')
// v82('Eas') // Error: Argument of type '"Eas"' is not assignable to parameter of type 'Direction'.

// 交叉类型
type V8Student = {
  school: string
  class: string
}
type V8Teacher = {
  subject: string
  grade: string
}
type V8School = V8Teacher & V8Student
let v811: V8School = {
  school: '小学',
  class: '一年级',
  subject: '数学',
  grade: 'A',
}
console.log(v811)

type V8School2 = V8Teacher | V8Student
// 其他一个类型写满, 就不会报错
let v812: V8School2 = {
  school: '小学',
  class: '一年级',
}
console.log(v812)

console.log()
console.log()
console.log('9.枚举类型tsc提示===========================================')

console.log()
console.log()
console.log('10.类型断言=================================================')
let vx1: any = '123'
let lenx11: number = (vx1 as string).length
let lenx12: number = (<string>vx1).length

const objectC = {
  name: '张三',
  age: 18,
}
// info = objectC as typeof objectC
let info = {} as typeof objectC
